package main;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class Starter {

	public static void main(String[] args) {
		//String path = "/home/SSWDaemon/";
		String path = "";
		Properties configFile = new Properties();
		try {
			configFile.load(new FileInputStream(path+"config.properties"));
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		String mysqlhost = configFile.getProperty("mysqlhost");
		String mysqlbasename = configFile.getProperty("mysqlbasename");
		String mysqlusername = configFile.getProperty("mysqlusername");
		String mysqlpassword = configFile.getProperty("mysqlpassword");
		
		String sourcename = configFile.getProperty("sourcename");
		String agg_period = configFile.getProperty("aggregate_period");

		MySqlConnect mysql = new MySqlConnect(mysqlhost, mysqlbasename, mysqlusername, mysqlpassword);
		mysql.readDbStructure(path + sourcename + ".xml");
		mysql.createTablesXML();
		try {
			Source data_source = (Source) Class.forName("main." + sourcename).newInstance();
			
			String[] params = configFile.getProperty(sourcename + "_properties").split(", ");
			data_source.setParameters(params, Integer.parseInt(agg_period));
			Daemon daemon = new Daemon(data_source, mysql);
			daemon.start();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		

	}
}
